package com.kaifamiao.demo.d0820;

import java.util.*;

public class Demo05 {

    public static void main(String[] args) {
        List collection = new ArrayList();
        // 添加元素
        collection.add(2);
        collection.add("a");
        collection.add('b');

        System.out.println(collection);
        System.out.println(collection.size()); // 3
        System.out.println(collection.isEmpty()); // false
        System.out.println(collection.contains("a")); // true

        Collection collection1 = new LinkedList();
        collection1.addAll(collection);

        System.out.println(collection1);

        // 删除
//        System.out.println(collection.remove(1));
//        System.out.println(collection1.removeAll(collection));
//        System.out.println(collection1);

//        collection.clear();
        System.out.println(collection);

        // 取元素
//        Iterator iterator = collection.iterator();
//        while(iterator.hasNext()){
//            System.out.println(iterator.next());
//        }

        // List
        Object obj = collection.get(0);
        System.out.println(obj);

        collection.add(0, 3);
        System.out.println(collection);

        collection.set(0, 6);
        System.out.println(collection);


        System.out.println(collection.remove(1));

        LinkedList list = new LinkedList();

        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.add(4);
        list.addLast(5);
        list.addLast(6);

        System.out.println(list);
//        System.out.println(list.pollFirst());
//        System.out.println(list.peekFirst());
        System.out.println(list.indexOf(5));
        System.out.println(list.lastIndexOf(5));
        System.out.println(list);
    }
}
